package com.example.administrator.x2picturetransliteration.Home.Presenter.Activity;

import android.content.Context;

import com.alibaba.fastjson.JSON;
import com.example.administrator.x2picturetransliteration.Base.BasePresenter;
import com.example.administrator.x2picturetransliteration.Base.HttpGo;
import com.example.administrator.x2picturetransliteration.Bean.CommonProblemBean;
import com.example.administrator.x2picturetransliteration.Bean.HttpDataBean;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import rx.subscriptions.CompositeSubscription;

/**
 * 常见问题
 * Created by Administrator on 2019/9/9.
 */

public class CommonProblemPresenter extends BasePresenter{

    public CommonProblemPresenter(Context context, CompositeSubscription mCompositeSubscription) {
        super(context, mCompositeSubscription);
    }

    /** 常见问题 */
    private Integer listPageNum = 1;
    public void list(boolean Refresh, final Callback mCallback){

        if (Refresh)listPageNum = 1;

        Map<String,String> httpdata = new HashMap<>();
        httpdata.put("page",listPageNum + "");
        httpdata.put("limit","10");

        mCompositeSubscription.add(

                mHttpGo.postSubscription("sys_question/list", httpdata,null, new HttpGo.HttpGoCallback() {
                    @Override
                    public void onError(Throwable e) {

                    }

                    @Override
                    public void onNext(HttpDataBean httpDataBean) {

                        if (httpDataBean.getCode()==0){

                            if (httpDataBean.getData()!=null){

                                List<CommonProblemBean> mdata = JSON.parseArray(httpDataBean.getData()+"",CommonProblemBean.class);

                                if (mdata.size()>0){

                                    listPageNum = listPageNum + 1;
                                    mCallback.getData(mdata);
                                }
                            }
                        }
                    }
                })
        );
    }

}
